package com.example.xmind2testcase.controller;

import com.example.xmind2testcase.pojo.Project;
import com.example.xmind2testcase.pojo.TestPlain;
import com.example.xmind2testcase.service.ProjectService;
import com.example.xmind2testcase.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProjectManageController {

    @Autowired
    private ProjectService projectService;

    @GetMapping("/project/getlist")
    public R getProjectList(){
        List<Project> projectList = projectService.getProjectList();
        return R.ok(projectList);
    }


    @PostMapping("/project/addproject/{projectName}")
    public R addproject(@PathVariable("projectName") String projectName){

        Project project1 = new Project();
        project1.setProjectName(projectName);
        Project project = projectService.addProject(project1);

        return R.ok(project);
    }

    @PostMapping("/project/addtestplain/{projectId}/{testPlain}")
    public R addTestPlan(@PathVariable("projectId") Long projectId,@PathVariable("testPlain") String testPlain){
        TestPlain testPlain1 = new TestPlain();
        testPlain1.setTestPlainName(testPlain);
        testPlain1.setProjectId(projectId);
        TestPlain testPlain2 = projectService.addTestPlain(testPlain1);
        return R.ok(testPlain2);
    }

    @GetMapping("/project/gettestplain/{projectId}")
    public R getTestPlanList(@PathVariable("projectId") Long projectId){
        List<TestPlain> projectList = projectService.getTestPlanList(projectId);
        return R.ok(projectList);
    }

}
